package com.briup.jz.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.briup.jz.bean.BasePrivilege;
import com.briup.jz.bean.BasePrivilegeExample;
import com.briup.jz.bean.BaseRole;
import com.briup.jz.bean.BaseRoleExample;
import com.briup.jz.dao.BasePrivilegeMapper;
import com.briup.jz.dao.BaseRoleMapper;
import com.briup.jz.service.IPrivilegeService;
import com.briup.jz.utils.CustomerException;
@Service
public class PrivilegeServiceImpl implements IPrivilegeService{
	
	 	@Resource
	    private BasePrivilegeMapper privilegeMapper;


	    @Override
	    public List<BasePrivilege> findAll() {
	        return privilegeMapper.selectByExample(new BasePrivilegeExample());
	    }

	    @Override
	    public BasePrivilege findById(long id) {
	        return privilegeMapper.selectByPrimaryKey(id);
	    }

	    @Override
	    public void saveOrEdit(BasePrivilege privilege) throws CustomerException {
	        if(privilege.getId()==null){
	        	privilegeMapper.insert(privilege);
	        }else{
	            if(privilegeMapper.selectByPrimaryKey(privilege.getId())==null){
	                throw new CustomerException("修改失败，数据不存在");
	            }
	            privilegeMapper.updateByPrimaryKey(privilege);
	        }
	    }

	    @Override
	    public void delById(long id){
	        if(privilegeMapper.selectByPrimaryKey(id)==null){
	            System.out.println("shuju"+privilegeMapper.selectByPrimaryKey(id));
	            throw new CustomerException("删除失败，数据不存在");
	        }
	        privilegeMapper.deleteByPrimaryKey(id);
	    }
}
